<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>menubuttonrenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_style_app_menubuttonrenderer.js.html">menubuttonrenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Renderer for {@link goog.ui.style.app.MenuButton}s and
<a name="line17"></a> * subclasses.
<a name="line18"></a> *
<a name="line19"></a> * @author attila@google.com (Attila Bodis)
<a name="line20"></a> * @author gveen@google.com (Greg Veen)
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.ui.style.app.MenuButtonRenderer&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.a11y.aria.Role&#39;);
<a name="line26"></a>goog.require(&#39;goog.array&#39;);
<a name="line27"></a>goog.require(&#39;goog.dom&#39;);
<a name="line28"></a>goog.require(&#39;goog.style&#39;);
<a name="line29"></a>goog.require(&#39;goog.ui.ControlContent&#39;);
<a name="line30"></a>goog.require(&#39;goog.ui.Menu&#39;);
<a name="line31"></a>goog.require(&#39;goog.ui.MenuRenderer&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.style.app.ButtonRenderer&#39;);
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>
<a name="line36"></a>/**
<a name="line37"></a> * Renderer for {@link goog.ui.style.app.MenuButton}s.  This implementation
<a name="line38"></a> * overrides {@link goog.ui.style.app.ButtonRenderer#createButton} to insert a
<a name="line39"></a> * dropdown element into the content element after the specified content.
<a name="line40"></a> * @constructor
<a name="line41"></a> * @extends {goog.ui.style.app.ButtonRenderer}
<a name="line42"></a> */
<a name="line43"></a>goog.ui.style.app.MenuButtonRenderer = function() {
<a name="line44"></a>  goog.ui.style.app.ButtonRenderer.call(this);
<a name="line45"></a>};
<a name="line46"></a>goog.inherits(goog.ui.style.app.MenuButtonRenderer,
<a name="line47"></a>    goog.ui.style.app.ButtonRenderer);
<a name="line48"></a>goog.addSingletonGetter(goog.ui.style.app.MenuButtonRenderer);
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line53"></a> * by this renderer.
<a name="line54"></a> * @type {string}
<a name="line55"></a> */
<a name="line56"></a>goog.ui.style.app.MenuButtonRenderer.CSS_CLASS =
<a name="line57"></a>    goog.getCssName(&#39;goog-menu-button&#39;);
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>/**
<a name="line61"></a> * Array of arrays of CSS classes that we want composite classes added and
<a name="line62"></a> * removed for in IE6 and lower as a workaround for lack of multi-class CSS
<a name="line63"></a> * selector support.
<a name="line64"></a> * @type {Array.&lt;Array.&lt;string&gt;&gt;}
<a name="line65"></a> */
<a name="line66"></a>goog.ui.style.app.MenuButtonRenderer.IE6_CLASS_COMBINATIONS = [
<a name="line67"></a>  [goog.getCssName(&#39;goog-button-base-rtl&#39;),
<a name="line68"></a>   goog.getCssName(&#39;goog-menu-button&#39;)],
<a name="line69"></a>
<a name="line70"></a>  [goog.getCssName(&#39;goog-button-base-hover&#39;),
<a name="line71"></a>   goog.getCssName(&#39;goog-menu-button&#39;)],
<a name="line72"></a>
<a name="line73"></a>  [goog.getCssName(&#39;goog-button-base-focused&#39;),
<a name="line74"></a>   goog.getCssName(&#39;goog-menu-button&#39;)],
<a name="line75"></a>
<a name="line76"></a>  [goog.getCssName(&#39;goog-button-base-disabled&#39;),
<a name="line77"></a>   goog.getCssName(&#39;goog-menu-button&#39;)],
<a name="line78"></a>
<a name="line79"></a>  [goog.getCssName(&#39;goog-button-base-active&#39;),
<a name="line80"></a>   goog.getCssName(&#39;goog-menu-button&#39;)],
<a name="line81"></a>
<a name="line82"></a>  [goog.getCssName(&#39;goog-button-base-open&#39;),
<a name="line83"></a>   goog.getCssName(&#39;goog-menu-button&#39;)],
<a name="line84"></a>
<a name="line85"></a>  [goog.getCssName(&#39;goog-button-base-active&#39;),
<a name="line86"></a>   goog.getCssName(&#39;goog-button-base-open&#39;),
<a name="line87"></a>   goog.getCssName(&#39;goog-menu-button&#39;)]
<a name="line88"></a>];
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Returns the ARIA role to be applied to menu buttons, which
<a name="line93"></a> * have a menu attached to them.
<a name="line94"></a> * @return {goog.a11y.aria.Role} ARIA role.
<a name="line95"></a> * @override
<a name="line96"></a> */
<a name="line97"></a>goog.ui.style.app.MenuButtonRenderer.prototype.getAriaRole = function() {
<a name="line98"></a>  // If we apply the &#39;button&#39; ARIA role to the menu button, the
<a name="line99"></a>  // screen reader keeps referring to menus as buttons, which
<a name="line100"></a>  // might be misleading for the users. Hence the ARIA role
<a name="line101"></a>  // &#39;menu&#39; is assigned.
<a name="line102"></a>  return goog.a11y.aria.Role.MENU;
<a name="line103"></a>};
<a name="line104"></a>
<a name="line105"></a>
<a name="line106"></a>/**
<a name="line107"></a> * Takes the button&#39;s root element and returns the parent element of the
<a name="line108"></a> * button&#39;s contents.  Overrides the superclass implementation by taking
<a name="line109"></a> * the nested DIV structure of menu buttons into account.
<a name="line110"></a> * @param {Element} element Root element of the button whose content element
<a name="line111"></a> *     is to be returned.
<a name="line112"></a> * @return {Element} The button&#39;s content element.
<a name="line113"></a> * @override
<a name="line114"></a> */
<a name="line115"></a>goog.ui.style.app.MenuButtonRenderer.prototype.getContentElement =
<a name="line116"></a>    function(element) {
<a name="line117"></a>  return goog.ui.style.app.MenuButtonRenderer.superClass_.getContentElement
<a name="line118"></a>      .call(this, element);
<a name="line119"></a>};
<a name="line120"></a>
<a name="line121"></a>
<a name="line122"></a>/**
<a name="line123"></a> * Takes an element, decorates it with the menu button control, and returns
<a name="line124"></a> * the element.  Overrides {@link goog.ui.style.app.ButtonRenderer#decorate} by
<a name="line125"></a> * looking for a child element that can be decorated by a menu, and if it
<a name="line126"></a> * finds one, decorates it and attaches it to the menu button.
<a name="line127"></a> * @param {goog.ui.Control} control goog.ui.MenuButton to decorate the element.
<a name="line128"></a> * @param {Element} element Element to decorate.
<a name="line129"></a> * @return {Element} Decorated element.
<a name="line130"></a> * @override
<a name="line131"></a> */
<a name="line132"></a>goog.ui.style.app.MenuButtonRenderer.prototype.decorate =
<a name="line133"></a>    function(control, element) {
<a name="line134"></a>  var button = /** @type {goog.ui.MenuButton} */ (control);
<a name="line135"></a>  // TODO(attila):  Add more robust support for subclasses of goog.ui.Menu.
<a name="line136"></a>  var menuElem = goog.dom.getElementsByTagNameAndClass(
<a name="line137"></a>      &#39;*&#39;, goog.ui.MenuRenderer.CSS_CLASS, element)[0];
<a name="line138"></a>  if (menuElem) {
<a name="line139"></a>    // Move the menu element directly under the body (but hide it first to
<a name="line140"></a>    // prevent flicker; see bug 1089244).
<a name="line141"></a>    goog.style.showElement(menuElem, false);
<a name="line142"></a>    goog.dom.appendChild(goog.dom.getOwnerDocument(menuElem).body, menuElem);
<a name="line143"></a>
<a name="line144"></a>    // Decorate the menu and attach it to the button.
<a name="line145"></a>    var menu = new goog.ui.Menu();
<a name="line146"></a>    menu.decorate(menuElem);
<a name="line147"></a>    button.setMenu(menu);
<a name="line148"></a>  }
<a name="line149"></a>
<a name="line150"></a>  // Let the superclass do the rest.
<a name="line151"></a>  return goog.ui.style.app.MenuButtonRenderer.superClass_.decorate.call(this,
<a name="line152"></a>      button, element);
<a name="line153"></a>};
<a name="line154"></a>
<a name="line155"></a>
<a name="line156"></a>/**
<a name="line157"></a> * Takes a text caption or existing DOM structure, and returns the content and
<a name="line158"></a> * a dropdown arrow element wrapped in a pseudo-rounded-corner box.  Creates
<a name="line159"></a> * the following DOM structure:
<a name="line160"></a> *  &lt;div class=&quot;goog-inline-block goog-button-outer-box&quot;&gt;
<a name="line161"></a> *    &lt;div class=&quot;goog-inline-block goog-button-inner-box&quot;&gt;
<a name="line162"></a> *      &lt;div class=&quot;goog-button-pos&quot;&gt;
<a name="line163"></a> *        &lt;div class=&quot;goog-button-top-shadow&quot;&gt;&amp;nbsp;&lt;/div&gt;
<a name="line164"></a> *        &lt;div class=&quot;goog-button-content&quot;&gt;
<a name="line165"></a> *          Contents...
<a name="line166"></a> *          &lt;div class=&quot;goog-menu-button-dropdown&quot;&gt; &lt;/div&gt;
<a name="line167"></a> *        &lt;/div&gt;
<a name="line168"></a> *      &lt;/div&gt;
<a name="line169"></a> *    &lt;/div&gt;
<a name="line170"></a> *  &lt;/div&gt;
<a name="line171"></a> * @param {goog.ui.ControlContent} content Text caption or DOM structure to wrap
<a name="line172"></a> *     in a box.
<a name="line173"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line174"></a> * @return {Element} Pseudo-rounded-corner box containing the content.
<a name="line175"></a> * @override
<a name="line176"></a> */
<a name="line177"></a>goog.ui.style.app.MenuButtonRenderer.prototype.createButton = function(content,
<a name="line178"></a>    dom) {
<a name="line179"></a>  var contentWithDropdown = this.createContentWithDropdown(content, dom);
<a name="line180"></a>  return goog.ui.style.app.MenuButtonRenderer.superClass_.createButton.call(
<a name="line181"></a>      this, contentWithDropdown, dom);
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/** @override */
<a name="line186"></a>goog.ui.style.app.MenuButtonRenderer.prototype.setContent = function(element,
<a name="line187"></a>    content) {
<a name="line188"></a>  var dom = goog.dom.getDomHelper(this.getContentElement(element));
<a name="line189"></a>  goog.ui.style.app.MenuButtonRenderer.superClass_.setContent.call(
<a name="line190"></a>      this, element, this.createContentWithDropdown(content, dom));
<a name="line191"></a>};
<a name="line192"></a>
<a name="line193"></a>
<a name="line194"></a>/**
<a name="line195"></a> * Inserts dropdown element as last child of existing content.
<a name="line196"></a> * @param {goog.ui.ControlContent} content Text caption or DOM structure.
<a name="line197"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document ineraction.
<a name="line198"></a> * @return {Array.&lt;Node&gt;} DOM structure to be set as the button&#39;s content.
<a name="line199"></a> */
<a name="line200"></a>goog.ui.style.app.MenuButtonRenderer.prototype.createContentWithDropdown =
<a name="line201"></a>    function(content, dom) {
<a name="line202"></a>  var caption = dom.createDom(&#39;div&#39;, null, content, this.createDropdown(dom));
<a name="line203"></a>  return goog.array.toArray(caption.childNodes);
<a name="line204"></a>};
<a name="line205"></a>
<a name="line206"></a>
<a name="line207"></a>/**
<a name="line208"></a> * Returns an appropriately-styled DIV containing a dropdown arrow.
<a name="line209"></a> * Creates the following DOM structure:
<a name="line210"></a> *    &lt;div class=&quot;goog-menu-button-dropdown&quot;&gt; &lt;/div&gt;
<a name="line211"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line212"></a> * @return {Element} Dropdown element.
<a name="line213"></a> */
<a name="line214"></a>goog.ui.style.app.MenuButtonRenderer.prototype.createDropdown = function(dom) {
<a name="line215"></a>  return dom.createDom(&#39;div&#39;, goog.getCssName(this.getCssClass(), &#39;dropdown&#39;));
<a name="line216"></a>};
<a name="line217"></a>
<a name="line218"></a>
<a name="line219"></a>/**
<a name="line220"></a> * Returns the CSS class to be applied to the root element of components
<a name="line221"></a> * rendered using this renderer.
<a name="line222"></a> * @return {string} Renderer-specific CSS class.
<a name="line223"></a> * @override
<a name="line224"></a> */
<a name="line225"></a>goog.ui.style.app.MenuButtonRenderer.prototype.getCssClass = function() {
<a name="line226"></a>  return goog.ui.style.app.MenuButtonRenderer.CSS_CLASS;
<a name="line227"></a>};
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/** @override */
<a name="line231"></a>goog.ui.style.app.MenuButtonRenderer.prototype.getIe6ClassCombinations =
<a name="line232"></a>    function() {
<a name="line233"></a>  return goog.ui.style.app.MenuButtonRenderer.IE6_CLASS_COMBINATIONS;
<a name="line234"></a>};
</pre>


</body>
</html>
